package com.jk.dmconsumer.controller;



import com.jk.dmcommon.entity.OrderEntity;
import com.jk.dmcommon.entity.ShippingEntity;
import com.jk.dmcommon.entity.CouponEntity;
import com.jk.dmcommon.entity.TreeEntity;
import com.jk.dmcommon.entity.LeaveEntity;
import com.jk.dmcommon.entity.SessionEntity;
import com.jk.dmconsumer.service.TreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jk.dmcommon.LybEntity.UserEntity;
import java.util.List;

/**
 * @author 赵优秀
 * @version 1.0.0
 * @ClassName TreeController.java
 * @Description TODO
 * @createTime 2021年09月07日 11:20:00
 */
@RequestMapping("tree")
@RestController
public class TreeController {
    @Autowired
    private TreeService treeService;
    /**
     * @title 树
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/7 19:35
     * @throws
     */
    @RequestMapping("getTree")
    public List<TreeEntity> getTree(Integer pid){
        return treeService.getTree(pid);
    }
    /**
     * @title 回显
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/7 19:42
     * @throws
     * @return
     */
    @RequestMapping("getByid")
    public UserEntity getByid(){
        UserEntity user = treeService.getByid();
        return user;
    }

    /**
     * @title 修改
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/7 20:38
     * @throws
     */

    @RequestMapping("updateUser")
    public String updateUser(UserEntity user){
        return treeService.updateUser(user);
    }

    /**
     * @title 查询订单
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/8 11:50
     * @throws
     */
    @RequestMapping("findAddress")
    public List<ShippingEntity> findAddress(){
        return treeService.findAddress();
    }
    /**
     * @title 新增收货地址
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/8 15:43
     * @throws
     */
    @RequestMapping("addAddress")
    public void addAddress(ShippingEntity shipping){
        treeService.addAddress(shipping);
    }
    /**
     * @title 删除
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/8 16:28
     * @throws
     */
    @RequestMapping("delAddress")
    public void delAddress(Integer id){
        treeService.delAddress(id);
    }
    /**
     * @title 回显地址
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/8 16:47
     * @throws
     */
    @RequestMapping("getAddress")
    public ShippingEntity getAddress(Integer id){
        return treeService.getAddress(id);
    }

    /**
     * @title 查询优惠券
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/8 19:03
     * @throws
     */
    @RequestMapping("findCoupon")
    public List<CouponEntity> findCoupon(CouponEntity coupon){
        if(coupon.getYesUse()==null && coupon.getPast()==null){
            coupon.setNoUse(1);
        }
        return treeService.findCoupon(coupon);
    }
    /**
     * @title 查询订单
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/8 21:25
     * @throws
     */
    @RequestMapping("findOrder")
    public String findOrder(OrderEntity orderEntity){
        orderEntity.setBuyUserId(2);
        List<OrderEntity> list = treeService.findOrder(orderEntity);
        OrderEntity[] arr = list.toArray(new OrderEntity[0]);
        String str = "";
        String status="";
        String caozuo = "";

        for(int i=0;i<arr.length;i++){
            Double price = arr[i].getRealityShopTotal();
            String id = arr[i].getId();
            if(arr[i].getOrderCondition()==0){
                status="未支付";
                caozuo= "<a href='../payment/aliapy?price="+price+"&id="+id+"'>付款</a>";
            }
            if(arr[i].getOrderCondition()==1){
                status="已支付";
                caozuo="";
            }
            if(arr[i].getOrderCondition()==2){
                status="关闭";
            }
            if(arr[i].getOrderCondition()==3){
                status="完成";
            }
            if(arr[i].getOrderCondition()==4){
                status="退款中";
            }
            str+=" <div class=\"next-col order-list-item\" data-spm=\"item_0\">\n" +
                    "   <div class=\"next-row order-list-item-header\" data-spm-anchor-id=\"a2oeg.orderlist.item_0.i0.6edc1ae6n1LlHv\">\n" +
                    "    订单号："+arr[i].getOrderId()+"\n" +
                    "   </div>\n" +
                    "   <div class=\"next-row order-list-item-bottom\">\n" +
                    "    <div class=\"next-col project-name\" style=\"width: 390px;\">\n" +
                    "     <div class=\"next-row project-name-wrapper\" data-spm=\"list\">\n" +
                    "      <div class=\"next-col next-col-4 project-name-img\" data-spm=\"ditem_0\">\n" +
                    "       <img src=\""+arr[i].getShopEntity().getGoodsImg()+"\" />\n" +
                    "      </div>\n" +
                    "      <div class=\"next-col project-name-content\" data-spm=\"ditem_0\">\n" +
                    "       <div class=\"next-row project-name\">\n" +
                    "        "+arr[i].getShopEntity().getGoodsName()+"\n" +
                    "       </div>\n" +
                    "       <div class=\"next-row project-name-perform\">\n" +
                    "        <span>"+arr[i].getShopEntity().getOnlineDescription()+"</span>\n" +
                    "       </div>\n" +
                    "       <div class=\"next-row project-name-venue\">\n" +
                    "        "+arr[i].getShopEntity().getGoodsAdress()+"\n" +
                    "       </div>\n" +
                    "       <div class=\"next-row pick-type-icon undefined\"></div>\n" +
                    "      </div>\n" +
                    "     </div>\n" +
                    "    </div>\n" +
                    "    <div class=\"next-col ticket-number\" style=\"width: 144px;\">\n" +
                    "     <div class=\"next-row ticket-number-wrapper\">\n" +
                    "      "+arr[i].getShopCount()+"\n" +
                    "     </div>\n" +
                    "    </div>\n" +
                    "    <div class=\"next-col order-amount\" style=\"width: 130px;\">\n" +
                    "     <div class=\"next-col order-amount-wrapper\">\n" +
                    "      <div class=\"next-row order-amount-content\">\n" +
                    "       "+arr[i].getShopTotal()+"\n" +
                    "      </div>\n" +
                    "      <div class=\"next-row transportation-costs\">\n" +
                    "       (含运费￥0.00)\n" +
                    "      </div>\n" +
                    "     </div>\n" +
                    "    </div>\n" +
                    "    <div class=\"next-col transaction-status\" style=\"width: 130px;\">\n" +
                    "     <div class=\"next-col transaction-status-wrapper\">\n" +
                    "      <div class=\"next-row transaction-status-content\">\n" +
                    "       "+status+"\n" +
                    "       <a href=\"#\" onClick=\"toOrderDetail('"+arr[i].getOrderId()+"')\">订单详情</a>\n"+
                    "      </div>\n" +
                    "     </div>\n" +
                    "    </div>\n" +
                    "    <div class=\"next-col transaction-operation\" style=\"width: 210px;\">\n" +
                    "     <div class=\"next-col transaction-operation-wrapper\">\n" +
                    "      <div class=\"text-wrapper\">\n" +
                    "       <div class=\"next-row pick-seat-info\" data-exp=\"true\" within24=\"false\" ic_id=\"653214816931\" usercode=\"2212454453311\" data-spm=\"dnotice\" data-aplus-ae=\"x1_24fa9912\" data-spm-anchor-id=\"a2oeg.orderlist.item_0.dnotice.6edc1ae6n1LlHv\"></div>\n" +
                    "      </div>\n" +
                    "       "+caozuo+"\n" +
                    "     </div>\n" +
                    "    </div>\n" +
                    "   </div>\n" +
                    "  </div>";
        }
        return str;
    }
    /**
     * @title 查询场次
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/9 14:32
     * @throws
     */
    @RequestMapping("getSession")
    public List<SessionEntity> getSession(Integer goodsId){
        return treeService.getSession(goodsId);
    }
    /**
     * @title 获取档次
     * @description
     * @author 赵优秀
     * @updateTime 2021/9/9 15:35
     * @throws
     */
    @RequestMapping("getLeave")
    public List<LeaveEntity> getLeave(Integer id){
        return treeService.getLeave(id);
    }
    /**
     *
     * 获取登录用户Id
     */
    @RequestMapping("getUserId")
    public Integer getUserId(){
        return treeService.getByid().getUserId();
    }
}
